<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增入职员工')" />
    <th:block th:include="include :: select2-css" />
</head>
<body>
<div class="main-content">
    <form id="form-emp-add" class="form-horizontal">
        <h4 class="form-header h4">基本信息</h4>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>员工编号：</label>
                    <div class="col-sm-8">
                        <input name="badge" id="badge" placeholder="请输入员工编号" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>姓名：</label>
                    <div class="col-sm-8">
                        <div class="input-group">
                            <input name="name" onclick="selectDeptTree()" id="treeName" type="text" placeholder="请输入员工姓名" class="form-control" required>
                            <span class="input-group-addon"><i class="fa fa-search"></i></span>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">性别：</label>
                    <div class="col-sm-8">
                        <select name="gender" id="gender" class="form-control m-b" th:with="type=${@dict.getType('sys_user_sex')}">
                            <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>出生日期：</label>
                    <div class="col-sm-8">
                        <input type="text" name="birthDay" class="form-control" id="datetimepicker-demo-2" placeholder="请选择出生日期" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>公司：</label>
                    <div class="col-sm-8">
                        <select id="company" name="compID" class="form-control" th:onchange="getbumen(this.value)">
                            <option th:each="company:${companys}" th:value="${company.compID}" th:text="${company.title}"></option>
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>部门：</label>
                    <div class="col-sm-8">
                        <select id="odepartment" name="depID" class="form-control" th:onchange="getgangwei(this.value)">
                            <option th:each="odepartment:${departments}" th:value="${odepartment.DepID}" th:text="${odepartment.title}"></option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label">岗位：</label>
                    <div class="col-sm-8">
                        <select id="job" name = 'jobID' class="form-control">
                        </select>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>入职日期：</label>
                    <div class="col-sm-8">
                        <input type="text" name="joinDate" class="form-control" id="datetimepicker-demo-3" placeholder="请选择出生日期" required>
                    </div>
                </div>
            </div>
        </div>
        <div class="row">
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>联系电话：</label>
                    <div class="col-sm-8">
                        <input name="tel" placeholder="请输入联系电话" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
            <div class="col-sm-6">
                <div class="form-group">
                    <label class="col-sm-4 control-label"><span style="color: red; ">*</span>现住地址：</label>
                    <div class="col-sm-8">
                        <input name="address" placeholder="请输入现住地址" class="form-control" type="text" maxlength="30" required>
                    </div>
                </div>
            </div>
        </div>
    </form>
</div>

<div class="row">
    <div class="col-sm-offset-5 col-sm-10">
        <button type="button" class="btn btn-sm btn-primary" onclick="submitemp()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
    </div>
</div>
<th:block th:include="include :: footer" />
<th:block th:include="include :: select2-js" />
<th:block th:include="include :: datetimepicker-js" />

<script>
    var prefix = ctx + "empentry";

    $("#form-emp-add").validate({
        onkeyup: false,
        rules:{
            badge:{
                minlength: 9,
                maxlength: 9,
                remote: {
                    url: prefix + "/checkBadgeUnique",
                    type: "post",
                    dataType: "json",
                    data: {
                        badge: function () {
                            return $.common.trim($("#badge").val());
                        }
                    },
                    dataFilter: function(data, type) {
                        return $.validate.unique(data);
                    }
                }
            },
        },
        messages: {
            "badge": {
                remote: "员工编号已存在"
            }
        },
        focusCleanup: true
    });

    $(function(){
        <!-- datetimepicker示例 -->

        $("#datetimepicker-demo-2").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        $("#datetimepicker-demo-3").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });

        <!-- laydate示例 -->
        layui.use('laydate', function(){
            var laydate = layui.laydate;
            laydate.render({
                elem: '#laydate-demo-2',
                type: 'date'
            });

        });
    });



    function getbumen(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findDep",
            data : {
                "compID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#odepartment").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].depID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#odepartment").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:"  + textStatus);
            }
        });
    }

    function getgangwei(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findJob",
            data : {
                "DepID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#job").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].jobID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#job").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:"  + textStatus);
            }
        });
    } function getbumen(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findDep",
            data : {
                "compID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#odepartment").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].depID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#odepartment").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:"  + textStatus);
            }
        });
    }

    function getgangwei(value){
        var html = "";
        $.ajax({
            async : false,
            url : "/empentry/findJob",
            data : {
                "DepID" : value
            },
            type : "post",
            dataType : "json",
            success : function(data) {
                $("#job").empty();
                var arry = data;

                for(var i=0;i<arry.length;i++){
                    html+="<option value='"
                        +arry[i].jobID
                        +"'>"
                        +arry[i].title
                        +"</option>";
                }
                $("#job").append(html);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {

                alert("错误,请联系管理员,错误信息:"  + textStatus);
            }
        });
    }

    function submitemp() {

        if ($.validate.form()) {
            var data = $("#form-emp-add").serializeArray();
            $.operate.saveTab(prefix + "/add", data);
        }

    }

</script>
</body>
</html>
